// YujinSRHostView.h : interface of the CYujinSRHostView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_YUJINSRHOSTVIEW_H__F665A1B0_099C_4806_8B8B_8206F2E468A4__INCLUDED_)
#define AFX_YUJINSRHOSTVIEW_H__F665A1B0_099C_4806_8B8B_8206F2E468A4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <ddraw.h>

#include "VisionSys.h"	// Added by ClassView
#include "SetingColor.h"
#include "SetBoundary.h"
#include "Game.h"
#include "Ground.h"

#define KICK_OFF		0		//Situation Define 
#define PENALTY_KICK	1
#define FREE_KICK		2
#define FREE_BALL		3
#define GOALIE_KICK		4
#define DEFENSE			5

#define HEIGHT 480
#define WIDTH 640
#define	ZOOM_SCALE					3
#define	ZOOM_OFFX					114
#define ZOOM_OFFY					32
#define ZOOM_SIZE					64
#define ZOOM_HALFSIZE				32


class CYujinSRHostView : public CFormView
{
protected: // create from serialization only
	CYujinSRHostView();
	DECLARE_DYNCREATE(CYujinSRHostView)

public:
	//{{AFX_DATA(CYujinSRHostView)
	enum { IDD = IDD_YUJINSRHOST_FORM };
	CString	m_sInfo;
	int		m_nRobotPosition;
	BOOL	m_bAttackDefense;
	int		m_nAttackDir;
	int		m_robot1_left;
	int		m_robot1_right;
	int		m_robot2_left;
	int		m_robot2_right;
	int		m_robot3_left;
	int		m_robot3_right;
	int		m_robot4_left;
	int		m_robot4_right;
	int		m_robot5_left;
	int		m_robot5_right;
	BOOL	m_nRobot1Move;
	BOOL	m_nRobot2Move;
	BOOL	m_nRobot3Move;
	BOOL	m_nRobot4Move;
	BOOL	m_nRobot5Move;
	//}}AFX_DATA

// Attributes
public:

	CYujinSRHostDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CYujinSRHostView)
	public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual void OnInitialUpdate(); // called first time after construct
	virtual void OnDraw(CDC* pDC);
	//}}AFX_VIRTUAL

// Implementation
public:
	void StopHook();
	//////////////////////////////////////////////////
	int				m_nCheckKeyBoardHit;	//Key Board Message Check Flag True = Hit False =none
	int				PositionOfBall[2];		  //vision Class Data Backup
	BOOL			m_bCheckRobotMove;	//Robot Serial Move check Tab Mode Check 
	bool			m_bCheckDisplay;	//Display Mode True = Draw image; false  = Real image
	bool			m_bGameStart;		//Game Start = true; Stop =false
	double			m_nTime;
	double			m_nTime1;
	RobotObj		RobotPosition[6];	  //vision Class Data Backup
	RobotObj		oppRobotPosition[6]; //vision Class Data Backup
	BYTE			DisplayByteTypeImage[1300000];						//Image buffer
	long			DisplayGroundArray[480][640];						//Main Window Display Array 
	long			OneDisplayGroundArray[480*640];					//
	int				m_BLookupUB[256];									//LookUP YUV Table
	int				m_BLookupUG[256];									//LookUP YUV Table
	int				m_BLookupVG[256];									//LookUP YUV Table
	int				m_BLookupVR[256];									//LookUP YUV Table
	unsigned int	TwoArrybuf[480][640];						//YUV Data 
	CSetingColor	m_CSetColor;								//SetColor Dlg Class Valiable
	CSetBoundary	m_CSetBoundary;							//SetBoundary Dlg Class Valiable
	CGame			m_CGame;									//Game Class Valiable
	VisionSys		m_pVisionSys;									//Vision Class 
	void		SerialCommand();							//Keyboard Command Data Send Function
	void GameProcess(bool EvenOrOdd);						//Vision -> Strategy -> SendCommand
	void OnButtonVisionStart();							
	void OnButtonVisionStop();
	void SetColorConfig(int ColorID);						//Color Update
	void initalSetDlg(bool ChangeOrSet,int *LimitValue);	//SetcolorDlg Inital 

	void MinMaxYUVThresholding(int *Value,CPoint Lastpoint);//Thresholding of Camera Image 
															// Value is thresholding Range 
	void YUVTORGB(DWORD Data,long *BackupH,long *BackupL);
	void ConvertYUVRGB(unsigned int *pImagedata);
	void DisplayDD(unsigned int *pImage); //DirectX Display 
	void ReleaseDD(); //Destroy DirectX
	int InitDD();	  //Initial DirectX
	unsigned int * m_pImage;  //Image Address Pointer
	virtual ~CYujinSRHostView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	
	LPDIRECTDRAW		m_lpDD;				// Pointer to DirectDraw object
	LPDIRECTDRAWSURFACE	m_lpFrontBuffer;	// Pointer to front buffer
	LPDIRECTDRAWSURFACE	m_lpBackBuffer;		// Pointer to back buffer
	LPDIRECTDRAWCLIPPER	m_lpClipper;		// Pointer to clipper
	int		m_DataFormat;
// Generated message map functions
protected:
	//{{AFX_MSG(CYujinSRHostView)
	afx_msg void OnPaint();
	afx_msg void OnButtomMeteorsetup();
	afx_msg void OnDestroy();
	afx_msg void OnButtonLoadconfig();
	afx_msg void OnSetcolor();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnChangecolor();
	afx_msg void OnSetboundary();
	afx_msg void OnSetpixelsize();
	afx_msg void OnColortunning();
	afx_msg void OnButtonSaveconfig();
	afx_msg void OnButtongamestart();
	afx_msg void OnButtongamestop();
	afx_msg void OnAutoRadio1();
	afx_msg void OnAutoRadio2();
	afx_msg void OnAutoRadio3();
	afx_msg void OnAutoRadio4();
	afx_msg void OnAutoRadio5();
	afx_msg void OnAutoRadio6();
	afx_msg void OnAutoRadio7();
	afx_msg void OnAutoRadio8();
	afx_msg void OnComRadio1();
	afx_msg void OnComRadio2();
	afx_msg void OnRightRadio();
	afx_msg void OnLeftRadio();
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnSituationGoalie();
	afx_msg void OnSituationKickoff();
	afx_msg void OnSituationPenealty();
	afx_msg void OnSiturationFreeball();
	afx_msg void OnSiturationFreekick();
	afx_msg void OnSiturationGame();
	afx_msg void OnAutoRadiogame();
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnCheckAttack();
	afx_msg void OnComunicationMenuButton();
	afx_msg void OnGamemenuButton();
	afx_msg void OnSettingButton();
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	void OnRight();
	void OnLeft();
	void OnBACKWARD();
	void OnForward();

	CPoint BackUpBallPoint;
	int TestTime;
	int			m_nVkArray[5];
	BOOL		m_bSetVisionSystem;		//Vision System initial Check True= Set false = none
	int			m_nComportNum;
	void		ShowMenu(int TabNumber);
	void		ConvetrYUVtoRGBDisplay(unsigned int *pImagedata);
	
	CRect		m_rectMainGround;
	CGround		m_CGround;
	int			m_nfindFlag[11];			  //vision Class Data Backup
	CRect		SelectedRectInZoom; // SelectRect Point
	bool		m_bSetColor;	//SetColor SetupCheck  flag 
	bool		m_bEndZoom;	//end  Mouse Move to Setting Area flag
	bool		m_bBeginZoom; //start Mouse Move to Setting Area flag
	long		ZoomLeft;	//Zoom Left Position
	long		ZoomTop;	//Zoom Top  Position 
	BYTE		ZoomBuffer[17000];	  //64*64*4 = 16384	

	void ConvertVisionPoint(RobotDPosition *My,RobotDPosition *Op,BallDPosition *ball);	//Image to Ground size
	void Zoom(CPoint point);
};

#ifndef _DEBUG  // debug version in YujinSRHostView.cpp
inline CYujinSRHostDoc* CYujinSRHostView::GetDocument()
   { return (CYujinSRHostDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_YUJINSRHOSTVIEW_H__F665A1B0_099C_4806_8B8B_8206F2E468A4__INCLUDED_)
